package ph.com.gs3.formalistics.model.valueobjects.business;

import java.io.Serializable;

import org.json.JSONException;
import org.json.JSONObject;

public class Comment implements Serializable {

	private static final long serialVersionUID = -5094619468647713254L;

	private String dbId;
	private String webId;

	private String documentFormWebId;
	private String documentWebId;
	private String server;

	private String text;
	private String dateCreated;

	private String authorWebId;
	private String authorEmail;
	private String authorDisplayName;
	private String authorImageURL;

	private boolean isCurrentlyBeingProcessed = false;
	private boolean isOutgoing = false;
	private boolean markedForDeletion = false;

	private String pendingStubId;

	public static Comment createFromJSON(JSONObject rawComment, String sourceServer)
	        throws JSONException {

		Comment comment = new Comment();

		comment.setWebId(rawComment.getString("id"));
		comment.setDocumentFormWebId(rawComment.getString("form_id"));
		comment.setDocumentWebId(rawComment.getString("request_id"));
		comment.setServer(sourceServer);

		comment.setText(rawComment.getString("text"));
		comment.setDateCreated(rawComment.getString("date_created"));

		comment.setAuthorWebId(rawComment.getString("author_id"));
		comment.setAuthorEmail(rawComment.getString("author_email"));
		comment.setAuthorDisplayName(rawComment.getString("author_display_name"));
		comment.setAuthorImageURL(rawComment.getString("author_image_url"));

		return comment;

	}

	@Override
	public String toString() {

		String trimmedComment;

		if (text.length() > 10) {
			trimmedComment = text.substring(0, 10);
		} else {
			trimmedComment = text;
		}

		return dbId + " - " + trimmedComment;
	}

	// ========================================================
	// {{ Getters & Setters

	public String getDbId() {
		return dbId;
	}

	public void setDbId(String dbId) {
		this.dbId = dbId;
	}

	public String getWebId() {
		return webId;
	}

	public void setWebId(String webId) {
		this.webId = webId;
	}

	public String getDocumentFormWebId() {
		return documentFormWebId;
	}

	public void setDocumentFormWebId(String documentFormWebId) {
		this.documentFormWebId = documentFormWebId;
	}

	public String getDocumentWebId() {
		return documentWebId;
	}

	public void setDocumentWebId(String documentWebId) {
		this.documentWebId = documentWebId;
	}

	public String getServer() {
		return server;
	}

	public void setServer(String server) {
		this.server = server;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(String dateCreated) {
		this.dateCreated = dateCreated;
	}

	public String getAuthorWebId() {
		return authorWebId;
	}

	public void setAuthorWebId(String authorWebId) {
		this.authorWebId = authorWebId;
	}

	public String getAuthorEmail() {
	    return authorEmail;
    }

	public void setAuthorEmail(String authorEmail) {
	    this.authorEmail = authorEmail;
    }

	public String getAuthorDisplayName() {
		return authorDisplayName;
	}

	public void setAuthorDisplayName(String authorDisplayName) {
		this.authorDisplayName = authorDisplayName;
	}

	public String getAuthorImageURL() {
		return authorImageURL;
	}

	public void setAuthorImageURL(String authorImageURL) {
		this.authorImageURL = authorImageURL;
	}

	public boolean isCurrentlyBeingProcessed() {
		return isCurrentlyBeingProcessed;
	}

	public void setCurrentlyBeingProcessed(boolean isCurrentlyBeingProcessed) {
		this.isCurrentlyBeingProcessed = isCurrentlyBeingProcessed;
	}

	public String getPendingStubId() {
		return pendingStubId;
	}

	public void setPendingStubId(String pendingStubId) {
		this.pendingStubId = pendingStubId;
	}

	public boolean isOutgoing() {
		return isOutgoing;
	}

	public void setOutgoing(boolean isOutgoing) {
		this.isOutgoing = isOutgoing;
	}

	public boolean isMarkedForDeletion() {
		return markedForDeletion;
	}

	public void setMarkedForDeletion(boolean markedForDeletion) {
		this.markedForDeletion = markedForDeletion;
	}

	// }}

}
